﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE spObtenerFolio
	(
		@pnIdTabla	INT,
		@pnFolio	BIGINT OUT
	)
AS
BEGIN
	BEGIN TRAN;

	BEGIN TRY
		SELECT	@pnFolio = ISNULL(MAX(folio),0) + 1
		FROM	Folio
		Where	IdTabla = @pnIdTabla
		
		UPDATE	Folio
		SET		Folio = @pnFolio
		WHERE	IdTabla = @pnIdTabla

	END TRY
	BEGIN CATCH
		ROLLBACK TRAN;
		RAISERROR('Error en obtener folio',16,1)
		RETURN
	END CATCH
	
	COMMIT TRAN;

END
